using UnityEngine;

/// <summary>
/// 处理Slot点击的组件，使用BoxCollider检测
/// </summary>
public class SlotClickHandler : MonoBehaviour
{
    private RewardPageUI rewardPageUI;
    private int slotIndex;
    private bool isEnabled = true;

    public void Initialize(RewardPageUI ui, int index)
    {
        rewardPageUI = ui;
        slotIndex = index;
    }

    /// <summary>
    /// 启用/禁用点击
    /// </summary>
    public void SetEnabled(bool enabled)
    {
        isEnabled = enabled;
    }

    /// <summary>
    /// 检查Slot是否应该被禁用
    /// </summary>
    public bool ShouldBeDisabled()
    {
        if (rewardPageUI == null) return false;

        // 使用RewardPageUI的公共方法来检查禁用条件
        return rewardPageUI.ShouldSlotsBeDisabled();
    }

    /// <summary>
    /// 鼠标点击事件
    /// </summary>
    private void OnMouseDown()
    {
        if (!isEnabled) return;

        Debug.Log($"点击了Slot {slotIndex}");

        if (rewardPageUI != null)
        {
            rewardPageUI.OnSlotClicked(slotIndex);
        }
    }

    /// <summary>
    /// 鼠标悬停进入
    /// </summary>
    private void OnMouseEnter()
    {
        if (!isEnabled) return;

        // 可以添加悬停效果，比如改变边框颜色
        Renderer renderer = GetComponent<Renderer>();
        if (renderer != null)
        {
            renderer.material.color = new Color(0.8f, 0.8f, 1f); // 浅蓝色
        }
    }

    /// <summary>
    /// 鼠标悬停离开
    /// </summary>
    private void OnMouseExit()
    {
        if (!isEnabled) return;

        // 恢复原始颜色
        Renderer renderer = GetComponent<Renderer>();
        if (renderer != null)
        {
            renderer.material.color = Color.white;
        }
    }
}